package com.fly.zuul;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;

public class TokenFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        String token = exchange.getRequest().getQueryParams().getFirst("token");
        if (token == null || token.isEmpty()) {
            System.err.println("自定义全局拦截器+++");
            //设置返回值
            exchange.getResponse().setStatusCode(HttpStatus.OK);
            // 结束请求进行拦截
            //return exchange.getResponse().setComplete();
        }
        exchange.getResponse().setStatusCode(HttpStatus.OK);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return -100;
    }
}
